package main

func main() {
	done := make(chan struct{})
	c := make(chan int)
	//循环接收数据,range模式更加简洁
	go func() {
		defer close(done)
		//循环获取消息直到通道关闭
		for x := range c{
			println(x)
		}
	}()
	c <- 1
	c <- 2
	c <- 3
	close(c)
	<- done
}
